﻿using AiXiu.BLL;
using AiXiu.IBLL;
using AiXiu.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Web;

namespace AiXiu.WebSite
{
    /// <summary>
    /// 聊天记录处理程序
    /// </summary>
    public class ChatRecordHandler : IHttpHandler
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            // 取值
            int selfId = int.Parse(context.Request.QueryString["selfId"]);
            int otherId = int.Parse(context.Request.QueryString["otherId"]);
            int pageNumber = int.Parse(context.Request.QueryString["pageNumber"]);
            int pageSize = int.Parse(context.Request.QueryString["pageSize"]);
            // 读取列表
            IFriendManager friendManager = new FriendManager();
            List<Message> messages = friendManager.GetMessages(selfId, otherId, pageNumber, pageSize);
            // 返回结果
            string messageJson = JsonConvert.SerializeObject(messages, new UnixDateTimeConverter());
            context.Response.ContentType = "text/plain";
            context.Response.Write(messageJson);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}